<template>
  <el-dialog
    title="审核编辑"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="500px"
  >
    <el-form size="small" :model="form" :rules="formRules" ref="form">
      <el-form-item
        label="是否通过"
        prop="auditStatus"
        :label-width="formLabelWidth"
      >
        <el-radio v-model="form.auditStatus" label="10">通过</el-radio>
        <el-radio v-model="form.auditStatus" label="20">未通过</el-radio>
      </el-form-item>
      <el-form-item
        label="备注"
        :label-width="formLabelWidth"
        v-if="form.auditStatus == 20"
      >
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入备注"
          v-model="form.auditRemark"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">取 消</el-button>
        <el-button type="primary" @click="eidtLive" :loading="loading"
          >确 定</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import LiveApi from "@/api/live.js";
export default {
  components: {},
  data() {
    var auditStatus = (rule, value, callback) => {
      if (value === "" || value === 0) {
        callback(new Error("请选择状态"));
      } else {
        callback();
      }
    };

    return {
      filePath: "",
      formRules: {
        auditStatus: [
          {
            validator: auditStatus,
            required: true,
            trigger: ["blur", "change"],
          },
        ],
      },
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: true,
      loading: false,
    };
  },
  props: ["form", "categorys"],
  created() {},
  methods: {
    /*审核*/
    eidtLive() {
      let self = this;
      let params = {
        roomId: self.form.roomId,
        status: self.form.auditStatus,
        remark: self.form.auditRemark,
      };
      self.$refs.form.validate((valid) => {
        if (valid) {
          self.loading = true;
          LiveApi.auditRoom(params, true)
            .then((res) => {
              self.loading = false;
              ElMessage({
                message: "审核成功",
                type: "success",
              });
              self.dialogFormVisible(true);
            })
            .catch((error) => {
              self.loading = false;
            });
        }
      });
    },

    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("close", {
          type: "success",
          openDialog: false,
        });
      } else {
        this.$emit("close", {
          type: "error",
          openDialog: false,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.img {
  margin-top: 10px;
}
</style>
